unit uConstants;
(*

  eConsole message constants

*)
interface

Uses Messages,
     Windows,
     SysUtils;

Const wm_StartShell = wm_User;
      wm_ChildExit = wm_StartShell +1; (* The child process quit *)
      wm_ChildStarted = wm_ChildExit +1; (* The child process was successfully started *)
      wm_UseBitmap = wm_ChildStarted +1; (* Use the bitmap given in wParam as background bitmap now *)

Const WM_APPBAR_CALLBACK = wm_UseBitmap + 1;
Const AppSize = 100;

Type TOperatingSystem = (osNT4,           (* YES ! YES ! YES ! *)
                         osNT5,           (* Well, OK *)
                         osWin95,         (* Arglll *)
                         osWin98          (* Ugh *)
                         );

Type TOperatingSystems = Set of TOperatingSystem;
Const OSWin9x : TOperatingSystems = [osWin95, osWin98];
      OSWinNT : TOperatingSystems = [osNT4, osNT5];

    (* The current operating system *)
Var fOS : TOperatingSystem;

Function Min( a, b : LongInt ) : LongInt; register;
Function Max( a, b : LongInt ) : LongInt; register;

Function HomeDir : String;

Function DirAdd( const aDir, aFilename : String ) : String;

procedure RaiseLastWin32Error( const aPosition : String );
implementation

procedure RaiseLastWin32Error( const aPosition : String );
var
  LastError: DWORD;
  Error: EWin32Error;
begin
  LastError := GetLastError;
  if LastError <> ERROR_SUCCESS then
    Error := EWin32Error.CreateFmt(SWin32Error, [LastError,
      SysErrorMessage(LastError)])
  else
    Error := EWin32Error.Create(SUnkWin32Error);

  Error.Message := aPosition + ': ' + Error.Message;

  Error.ErrorCode := LastError;
  raise Error;
end;

Function Min( a, b : LongInt ) : LongInt; register;
Begin
  Result := a;
  If a > b then Result := b;
End;

Function Max( a, b : LongInt ) : LongInt; register;
Begin
  Result := a;
  If a < b then Result := b;
End;

Function HomeDir : String;
Var I : Integer;
Begin
  SetLength( Result, 255 );
  GetModuleFileName( hInstance, @Result[1], Length( Result ));
  I := Pred( Pos( #0, Result ));
  While (I > 0) and (Result[I] <> '\') do
    Dec( I );
  SetLength( Result, I );
End;

Function DirAdd( const aDir, aFilename : String ) : String;
(* Not completely right, but who cares ? *)
Begin
  If aDir[ Length( aDir )] = '\'
    then Result := aDir + aFilename
    else Result := aDir + '\' + aFilename;
End;

end.
